import { observable, action } from 'mobx'
import { post } from 'lib/net'
import CommonVM from 'cvm/common'
import * as api from 'lib/constants/api'

export default class SystemMsgVM extends CommonVM {
  constructor (props) {
    super()
    this.props = props
    this.fetchData()
  }

  // 反馈内容
  @observable contentValue = ''
  // 数据
  @observable data = []

  // 数据请求
  @action fetchData = async () => {
    this.fetchPage()
    let params = {
      Offset: this.pageInfo.page,
      Limit: this.pageInfo.size,
      UserInfoID: this.userId
    }
    let res = await post(api.SYSTEM_MESSAGE, params)
    if (res.state === 1) {
      let data = res.data || []
      if (this.pageInfo.page === 1) {
        this.data.splice(0, this.data.length, ...data)
      } else {
        this.data.splice(this.data.length, 0, ...data)
      }
      this.receivePage(res.data || [])
    } else {
      this.receivePage()
    }
  }

  // 修改内容
  @action handleChangeContent = e => {
    this.contentValue = e.target.value
  }

  // 意见反馈
  @action handleLoadMore = () => {
    this.fetchData()
  }
}
